package com.example.sellersale.controller;


import com.example.sellersale.entity.Goods;
import com.example.sellersale.entity.Order;
import com.example.sellersale.entity.User;
import com.example.sellersale.server.GoodsService;
import com.example.sellersale.server.OrderService;
import com.example.sellersale.server.UserService;
import com.example.sellersale.server.impl.GoodsServiceImpl;
import com.example.sellersale.server.impl.OrderServiceImpl;
import com.example.sellersale.server.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@CrossOrigin
@Transactional(rollbackFor = Exception.class)
public class ManagerController {
    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;

    /**
     * 活动指定时间内的订单信息
     * @param time
     * @return
     */
    @GetMapping("/timeOrder")
    public List<Order> speciallyTimeOrder(String time){
        return orderService.speciallyTimeOrder(time);
    }


    //获取所有的用户信息
    @GetMapping("/allUser")
    public List<User> allUser(){
        return userService.allUser();
    }
    //获取所有的订单信息
    @GetMapping("/allUserOrder")
    public List<Order> allOrder(){
        List<Order> orders = orderService.allUserOrder();
        return orders;
    }

    /**
     * 增加库存
     * @param goods
     * @return
     */
    @PostMapping("/addGoods")
    public Boolean addGoods(Goods goods){
        return goodsService.addGoods(goods);
    }

    /**
     * 修改订单状态
     * @param oId  订单id
     * @param gId  商品id
     * @return  是否修成功
     */
    @PostMapping("/editStatus")
    public boolean updateOrderStatus(String oId,String gId,String status){
        return orderService.updateOrderStatus(oId,gId,status);
    }


    /**
     *入库功能
     */
    @PostMapping("/save")
    public Boolean save(Goods goods){
        return null;
    }



}
